package com.ruoyi.web.controller.market.sys;

import java.util.List;
import java.util.Map;

import com.ruoyi.db.domain.SmsConfigInfo;
import com.ruoyi.sys.service.ISmsConfigInfoService;
import com.ruoyi.web.wapper.SmsConfigInfoWapper;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 短信管理Controller
 * 
 * @author admin
 * @date 2022-07-26
 */
@Controller
@RequestMapping("/sys/sms")
public class SmsConfigInfoController extends BaseController
{
    private String prefix = "sys/sms";

    @Autowired
    private ISmsConfigInfoService smsConfigInfoService;

    @RequiresPermissions("sys:sms:view")
    @GetMapping()
    public String sms()
    {
        return prefix + "/sms";
    }

    /**
     * 查询短信管理列表
     */
    @RequiresPermissions("sys:sms:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SmsConfigInfo smsConfigInfo)
    {
        startPage();
//        List<SmsConfigInfo> list = smsConfigInfoService.selectSmsConfigInfoList(smsConfigInfo);
        List<Map<String, Object>> mapList = smsConfigInfoService.selectSmsConfigInfoListMap(smsConfigInfo);
        mapList = new SmsConfigInfoWapper(mapList).wrap();
        return getDataTable(mapList);
    }

    /**
     * 导出短信管理列表
     */
    @RequiresPermissions("sys:sms:export")
    @Log(title = "短信管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SmsConfigInfo smsConfigInfo)
    {
        List<SmsConfigInfo> list = smsConfigInfoService.selectSmsConfigInfoList(smsConfigInfo);
        ExcelUtil<SmsConfigInfo> util = new ExcelUtil<SmsConfigInfo>(SmsConfigInfo.class);
        return util.exportExcel(list, "短信管理数据");
    }

    /**
     * 新增短信管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存短信管理
     */
    @RequiresPermissions("sys:sms:add")
    @Log(title = "短信管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SmsConfigInfo smsConfigInfo)
    {
        return toAjax(smsConfigInfoService.insertSmsConfigInfo(smsConfigInfo));
    }

    /**
     * 修改短信管理
     */
    @RequiresPermissions("sys:sms:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        SmsConfigInfo smsConfigInfo = smsConfigInfoService.selectSmsConfigInfoById(id);
        mmap.put("smsConfigInfo", smsConfigInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存短信管理
     */
    @RequiresPermissions("sys:sms:edit")
    @Log(title = "短信管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SmsConfigInfo smsConfigInfo)
    {
        return toAjax(smsConfigInfoService.updateSmsConfigInfo(smsConfigInfo));
    }

    /**
     * 删除短信管理
     */
    @RequiresPermissions("sys:sms:remove")
    @Log(title = "短信管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(smsConfigInfoService.deleteSmsConfigInfoByIds(ids));
    }


    /**
     * 修改短信配置
     */
    @RequiresPermissions("sys:sms:changeStatus")
    @Log(title = "短信管理", businessType = BusinessType.UPDATE)
    @PostMapping("/changeStatus")
    @ResponseBody
    public AjaxResult changeStatus(@RequestParam("useType") String useType, @RequestParam("id") Long id)
    {
        return smsConfigInfoService.changeStatus(id, useType);
    }

}
